import Cesium from '@czm';
import {
  g3x_defineClassProperties,
} from "@g3x/utils";

export default function(Ctor) {
  g3x_defineClassProperties(Ctor, [{
    key: 'availability',
    get() {

      function toInterval(options) {
        var start, stop;
        if (options.start) {
          start = Cesium.JulianDate.fromIso8601(options.start)
          if (options.stop) {
            stop = Cesium.JulianDate.fromIso8601(options.stop)
          } else if (options.during) {
            stop = Cesium.JulianDate.addSeconds(start, during, new Cesium.JulianDate());
          }
        }
        const {
          isStartIncluded,
          isStopIncluded,
          data
        } = options
        return {
          start,
          stop,
          isStartIncluded,
          isStopIncluded,
          data
        }
      }

      function getAvailability(timeIntervals_) {
        const timeIntervals = [];
        timeIntervals_.forEach(e => {
          const interval = toInterval(e);
          var result = new Cesium.TimeInterval(interval);
          timeIntervals.push(result);
        });
        const availability = new Cesium.TimeIntervalCollection(timeIntervals);
        return availability;
      }

      const availability = getAvailability(this.timeIntervals);

      return availability;
    }
  },{
    key: 'availability',
    get() {
      
    }
  }]);
}
